package com.wpen.unit.enums;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 任务计划类型
 * 
 * @author Wang Peng
 * @date 2022-12-01
 */
public enum ExecStatus {

	/**/
	Wait("W", "等待", 0),
	/**/
	Init("0", "初始化", 1),
	/**/
	Running("R", "运行中", 2),
	/**/
	Excption("E", "异常", 4),
	/**/
	Finished("S", "成功", 3),
	/**/
	;

	// 成员变量
	private String value; // value
	private String desc; // 描述
	private int level;

	// 构造方法
	private ExecStatus(String val, String desc, int level) {
		this.value = val;
		this.desc = desc;
		this.level = level;
	}

	public static boolean comp(String v1, String v2) {
		ExecStatus es1 = getType(v1);
		ExecStatus es2 = getType(v2);
		if (es1 != null && es2 != null) {
			return es2.getLevel() < es1.getLevel();
		}
		return false;
	}

	public static Map<String, String> getMap() {
		ExecStatus[] loops = ExecStatus.values();
		Map<String, String> map = new LinkedHashMap<String, String>();
		for (ExecStatus loop : loops) {
			map.put(loop.desc(), loop.value());
		}
		return map;
	}

	/**
	 * 通过value获取对象
	 */
	public static ExecStatus getType(String val) {
		for (ExecStatus c : ExecStatus.values()) {
			if (c.value().equals(val)) {
				return c;
			}
		}
		return null;
	}

	public String value() {
		return value;
	}

	public String desc() {
		return desc;
	}

	public int getLevel() {
		return level;
	}

}
